home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
music
/
stsynth.arc
/
SOUNDKEY.C
next >
Wrap
C/C++ Source or Header
|
1987-05-18
|
29KB
|
699 lines
/* SoundKey.c
David T. Jarvis
Atari ST -- Lattice C -- Version 052686
*/
#define SPACE_K 32 /* space key */
#define ESC_K 27 /* ESC key */
#define RETURN_K 13 /* return key */
#define DURA 1000 /* note duration */
#define TUNE_INC 6 /* adjust tuning by this much */
#define MAX_OCT 6 /* maximum octave */
#define MAX_VOL 15 /* maximum volume */
#define MAX_WAV 15 /* maximum waveform */
#define N_P_OCT 15 /* notes per octave */
#define MOUS_OFF 256 /* disable mouse */
#define MOUS_ON 257 /* enable mouse */
#define T_OUTLINE 0x10 /* text style--outline */
#define T_NORMAL 0x0 /* text style--normal */
#define T_SKEWED 0x0004 /* text style--skewed */
#define T_THICK 0X0001 /* text style--thick */
#define CH_ENA_R 7 /* voice channel enable(read) */
#define CH_ALO_W 128 /* channel,voice a lo,write */
#define CH_AHI_W 129 /* channel,voice a hi,write */
#define CH_BLO_W 130 /* " , " b lo, " */
#define CH_BHI_W 131 /* " , " b hi, " */
#define CH_CLO_W 132 /* " , " c lo, " */
#define CH_CHI_W 133 /* " , " c hi, " */
#define CH_ENA_W 135 /* voice channel enable(write) */
#define CH_AVL_W 136 /* channel a volume, write */
#define CH_BVL_W 137 /* " b " , " */
#define CH_CVL_W 138 /* " c " , " */
#define RG_ENV_W 140 /* envelope register, write */
#define RG_WAV_W 141 /* waveform register, write */
#define CONTERM 0X484 /* attributes of console */
#include <stdio.h> /* standard io library */
#include <osbind.h> /* GEMDOS,BIOS,XBIOS macros */
#include <ctype.h> /* character type macros */
#define Supexec(a) xbios(38,a) /* Exec routine,supervisor mode */
/* play contains the numbers to plug into the ST sound chip */
short int play[ MAX_OCT ][ N_P_OCT ] =
{
{ 3906,3689,3472,3189,3048,2906,2728,2551,2411,2272,2160,2049,1923,1817,1712 },
{ 1923,1817,1712,1633,1524,1436,1350,1275,1205,1136,1076,1016,954,902,850 },
{ 954,902,850,807,757,714,675,637,602,568,537,506,477,451,425 },
{ 477,451,425,401,378,358,338,318,301,284,268,253,239,225,212 },
{ 239,225,212,200,189,179,169,159,150,142,134,126,119,112,106 },
{ 119,112,106,100, 94, 89, 84, 79, 75, 71, 67, 63, 59, 54, 51 }
};
short int contrl[12],
intin[256], intout[256],
ptsin[256], ptsout[256],
workin[20], workout[100],
handle, i, j,
dvar, port_state,
key_rate,fast_key = 1,
x_note, y_note, z_note,
old_note = 0;
char c, x_low, x_high, y_low, y_high, z_low, z_high;
char *std_msg = "Press ESC to Exit ";
short int hold_n = 0, /* flag-- hold notes */
period = 10, /* period for sound waves */
wave = 0, /* waveform */
vol_a = MAX_VOL, /* voice a volume */
vol_b = MAX_VOL, /* voice b volume */
vol_c = MAX_VOL, /* voice c volume */
oct_a = 2, /* voice a octave */
oct_b = 2, /* voice b octave */
oct_c = 2, /* voice c octave */
tune = 6, /* tuning (added to pitch) */
tn_a=2,tn_b=2,tn_c=2, /* tuning for individual voices */
diss = 3; /* dissonance level */
int nonoise(); /* routine to disable noise */
main()
{
/* Check for correct resolution */
if (Getrez() != 1)
{
printf("Sorry, this program must be run in medium resolution.\n");
exit(0);
}
/* Initialize application */
appl_init();
handle=graf_handle( &dvar, &dvar, &dvar, &dvar );
for ( i = 0; i < 10; workin[ i++ ]=1 ); workin[ 10 ] = 2;
v_opnvwk( workin, &handle, workout );
/* Hide mouse, disable keyclick,bell, speed up keyboard repeat rate */
graf_mouse( MOUS_OFF, 0 );
Supexec(nonoise);
key_rate = Kbrate( 0x01,0x01 );
/* Initialize sound chip, enable channels a and b */
sound_off();
port_state = Giaccess( i, CH_ENA_R );
Giaccess( (port_state & 0xc0) | 56, CH_ENA_W );
/* Make music */
play_keys();
/* turn off the sound chip, restore initial state */
Giaccess( port_state, CH_ENA_W );
/* restore keyboard repeat rate, close application and exit */
Kbrate( (key_rate >> 8) & 0x00ff, key_rate & 0x00ff );
v_clsvwk( handle );
appl_exit();
}
play_keys()
{
register char c=' ', c2=' ';
keys_screen();
while (c != ESC_K)
{
if (Bconstat(2))
{
vol_c = 0;
c = Bconin(2); c = tolower(c);
switch(c)
{
case '1':
locate(22,1);
put_msg( "H=>Higher, L=>Lower, RETURN=>Done ");
x_note = play[ oct_a ][ 0 ] + tn_a;
y_note = play[ oct_b ][ 0 ] + tn_b;
sound_on();
do
{
c2 = Bconin(2); c2 = tolower(c2);
switch(c2)
{
case 'h':
if (tune)
{
tune -= TUNE_INC;
tn_a = tune/(oct_a+1);
tn_b = tune/(oct_b+1);
tn_c = tune/(oct_c+1);
x_note = play[ oct_a ][ 0 ] + tn_a;
y_note = play[ oct_b ][ 0 ] + tn_b;
sound_on();
dsp_vals();
}
break;
case 'l':
if (tune < TUNE_INC*5)
{
tune += TUNE_INC;
tn_a = tune/(oct_a+1);
tn_b = tune/(oct_b+1);
tn_c = tune/(oct_c+1);
y_note = play[ oct_b ][ 0 ] + tn_b;
x_note = play[ oct_a ][ 0 ] + tn_a;
sound_on();
dsp_vals();
}
break;
default:
break;
}
} while (c2 != RETURN_K );
sound_off();
put_msg( std_msg );
x_note = old_note;
break;